/**
 * 
 */
package by.imotaeva.printing_services.services.impl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.imotaeva.printing_services.dataaccess.FaqDao;
import by.imotaeva.printing_services.datamodel.Faq;
import by.imotaeva.printing_services.services.FaqService;

/**
 * @author Inna
 *
 */
@Service
public class FaqServiceImpl implements FaqService{
	private static final Logger LOGGER = LoggerFactory.getLogger(FaqServiceImpl.class);

	@Inject
	private FaqDao dao;
	
	@PostConstruct
	private void init() {
		// this method will be called by Spring after bean instantiation. Can be
		// used for any initialization process.
		LOGGER.info("Instance of FaqService is created. Class is: {}", getClass().getName());
	}
	
	@Override
	public Faq get(Long id) {
		Faq entity = dao.getById(id);
		return entity;
	}

	@Override
	public void saveOrUpdate(Faq faq) {
		if (faq.getId() == null) {
			LOGGER.debug("Save new: {}", faq);
			dao.insert(faq);
		} else {
			LOGGER.debug("Update: {}", faq);
			dao.update(faq);
		}    
		
	}

	@Override
	public void delete(Faq faq) {
		LOGGER.debug("Remove: {}", faq);
		dao.delete(faq.getId());
		
	}

	@Override
	public void deleteAll() {
		LOGGER.debug("Remove all products");
		dao.deleteAll();
	}

}
